﻿using SwenAssigment.Classes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SwenAssigment
{
    public partial class BookingCheckIn : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["gid"] != null & Session["gid"] != "" & Session["rarid"] != null & Session["rarid"] != "")
            {
                if (Label1.Text == "Label")
                {
                    string line = "select * from guest where Guest_ID='" + Session["gid"] + "'";
                    RADcon con = new RADcon();
                    string[] s = con.grestrieveone(line);
                    Label1.Text = s[1];
                    Label2.Text = s[2];
                    Label3.Text = s[3];
                    Label4.Text = s[4];
                    Label5.Text = s[5];
                    Label6.Text = Session["rarid"].ToString();
                    Label7.Text = System.DateTime.Now.ToShortDateString() + " " + System.DateTime.Now.ToShortTimeString();
                    if (Page.Request.UrlReferrer.LocalPath == "/GuestDetail.aspx")
                    {

                    }
                    else
                    {
                        Response.Redirect("RoomAvalibility.aspx");
                    }
                }
            }
            else
            {
                Response.Redirect("RoomAvalibility.aspx");
            }
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            RADcon con = new RADcon();
            Booking b = new Booking();
            b.guestid = int.Parse(Session["gid"].ToString());
            b.numadult = int.Parse(DropDownList2.Text);
            b.numchild = int.Parse(DropDownList3.Text);
            b.checkindt = System.DateTime.Now.ToShortDateString() + " " + System.DateTime.Now.ToShortTimeString();
            if (Calendar1.SelectedDate.ToShortDateString() == "1/1/0001")
            {
                b.pcheckoutdt = System.DateTime.Now.ToShortDateString() + " " + System.DateTime.Now.ToShortTimeString();
            }
            else
            {
                b.pcheckoutdt = Calendar1.SelectedDate.ToShortDateString();
            }
            b.proomtype = DropDownList1.Text;
            b.roomassign = int.Parse(Session["rarid"].ToString());
            bool bl = con.bcreate(b);
            if (bl == true)
            {
                string[] s = con.raretrieveone("select * from room where Room_ID='" + Session["rarid"] + "'");
                bool b2 = con.raupdate(int.Parse(s[0]), decimal.Parse(s[3]), "Occupied");
                if (b2 == true)
                {
                    Session["mystat"] = "Check In";
                    Response.Redirect("RoomAvalibility.aspx");
                }
            }
            else
            {
            }
        }
    }
}